package test1;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class Test {
    public static void main(String[] args) throws DocumentException {
        SAXReader reader = new SAXReader();
        Document document = reader.read(new File("xml-test\\src\\test1\\books.xml"));
        Element rootElement = document.getRootElement();
        List<Element> books = rootElement.elements("book");
        for (Element book : books) {
            Element name_ele = book.element("name");
            String name = name_ele.getText();
            Element home_ele = book.element("home");
            String home = home_ele.getText();
            Element date_ele = book.element("date");
            String date = date_ele.getText();
            Element price_ele = book.element("price");
            String price = price_ele.getText();

            Book bo = new Book(name, home, date, Double.parseDouble(price));
            System.out.println(bo);

        }
    }
}
